﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ECONTACT.DataLayer
{
    public class GiaoVienData
    {
        DataService m_GiaoVienData = new DataService();

        public DataTable LayDsGiaoVien()
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM GIAOVIEN");
            m_GiaoVienData.Load(cmd);
            return m_GiaoVienData;
        }

        public String LuuGiaoVien(String TenGV, DateTime NgaySinh, bool GioiTinh, String SDT, String Email, String DiaChi)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("sp_ThemGiaoVien");

                cmd.Parameters.Add("@TenGV", SqlDbType.NVarChar).Value = TenGV;
                cmd.Parameters.Add("@NgaySinh", SqlDbType.DateTime).Value = NgaySinh;
                cmd.Parameters.Add("@GioiTinh", SqlDbType.Bit).Value = GioiTinh;
                cmd.Parameters.Add("@SDT", SqlDbType.NVarChar).Value = SDT;
                cmd.Parameters.Add("@Email", SqlDbType.NVarChar).Value = Email;
                cmd.Parameters.Add("@DiaChi", SqlDbType.NVarChar).Value = DiaChi;

                m_GiaoVienData.LoadProc(cmd);
            }
            catch (System.Exception ex)
            {
                return ex.Message;
            }

            return "Success";
        }

        public String UpdateGiaoVien(String MAGV, String TenGV, DateTime NgaySinh, bool GioiTinh, String SDT, String Email, String DiaChi)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("sp_CapNhatGiaoVien");

                cmd.Parameters.Add("@MaGV", SqlDbType.VarChar).Value = MAGV;
                cmd.Parameters.Add("@TenGV", SqlDbType.NVarChar).Value = TenGV;
                cmd.Parameters.Add("@NgaySinh", SqlDbType.DateTime).Value = NgaySinh;
                cmd.Parameters.Add("@GioiTinh", SqlDbType.Bit).Value = GioiTinh;
                cmd.Parameters.Add("@SDT", SqlDbType.NVarChar).Value = SDT;
                cmd.Parameters.Add("@Email", SqlDbType.NVarChar).Value = Email;
                cmd.Parameters.Add("@DiaChi", SqlDbType.NVarChar).Value = DiaChi;

                m_GiaoVienData.LoadProc(cmd);
            }
            catch (System.Exception ex)
            {
                return ex.Message;
            }
            return "Success";
        }

        public void DeleteGiaoVien(String MaGV)
        {
            SqlCommand cmd = new SqlCommand("sp_XoaGiaoVien");
            cmd.Parameters.Add("@MaGV", SqlDbType.Int).Value = Convert.ToInt32(MaGV);

            m_GiaoVienData.LoadProc(cmd);
        }
    }
}
